<template>
  <div style="margin-top: -100px" class="bgcolor">
    <el-container>
      <el-header>猜你喜欢</el-header>
      <el-main>
        <el-row>
          <el-col
            :span="2"
            v-for="(o, index) in DataList"
            :key="index"
            :offset="index >= 0 ? DataList.length : 0"
          >
            <el-card :body-style="{ padding: '0px' }" style="width:200px; height:350px;margin-left:30px;" shadow="hover">
              <img
                :src="o.url"
                class="image"
                style="width:200px;height:200px;"
                />
              <div style="padding: 14px;margin-top:-50px;">
                <span>{{o.goods_name}}</span>
                <span style="margin-left:10px;">{{"价格:"+o.goods_price}}</span>
                <div class="bottom clearfix" style="margin-top:-50px;">
                  <time class="time">{{ currentDate }}</time>
                  <br>
                  <el-button type="text" class="button" @click="showPro(o.goods_id,o.goods_name,o.goods_price,o.goods_type,o.market_name,o.url)">查看商品</el-button>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-pagination background layout="prev, pager, next" 
         :page-size="PageSize"
         :page-count="PageCount"
         :current-page="CurrnetPage"
         @current-change="pageChange"
         >
        </el-pagination>
      </el-main>
      <el-footer>END</el-footer>
    </el-container>
  </div>
</template>
<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
body > .el-container {
  margin-bottom: 40px;
}
.bgcolor {
  background-color: white;
}
.time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
</style>
<script>
export default {
  data() {
    return {
      currentDate: new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+"-"+new Date().getHours()+"-"+new Date().getMinutes()+"-"+new Date().getSeconds(),
      PageSize:4,
      PageCount:10,
      CurrnetPage:1,
      DataList:[]
    }
  },
  methods:{
    pageChange(val){
      this.CurrentPage = val;
      let pageinfo = {
        'currentPage':this.CurrentPage,
        'pageSize':this.PageSize
      };
      this.axios.post("/api/shopping/getImage.php",pageinfo).then(res=>{
        if(res.data=="error"){
          alert("服务器出错了");
        }else{
            this.DataList = res.data;
            this.PageCount = res.data[0].pageCount;
            console.log(res.data);
        }
      });
    },
    showPro(goods_id,goods_name,goods_price,goods_type,market_name,goods_url){
      this.$router.push({name:"showProduce",params:{
        goods_id:goods_id,
        goods_name:goods_name,
        goods_price:goods_price,
        goods_type:goods_type,
        market_name:market_name,
        goods_url:goods_url
      }});
    }
  },
  created:function(){
      let pageInfo = {
        'currentPage':1,
        'pageSize':4
      };
      this.axios.post("/api/shopping/getImage.php",pageInfo).then(res=>{
            this.DataList = res.data;
            this.PageCount = res.data[0].pageCount;
      });
  }
}
</script>